import request from '@/utils/request'
// 环境监测
export function environmentTracking(method, data, bln) {
  console.info('methods', method)
  let url = ''
  let value = null

  if (bln) {
    url = '/EnvironmentTracking/' + data.id
    value = data.value
  } else {
    url = '/EnvironmentTracking/Search'
    value = data
  }
  return request({ url, method, data: value })
}

// 传感器基站
export function sensorStation(method, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/EnvironmentTrackingSetting/' + data.id
    value = data.value
  } else {
    url = '/EnvironmentTrackingSetting/Search'
    value = data
  }
  return request({
    url,
    method,
    data: value
  })
}

// 员工相关
export function employee(method, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/Employee/' + data.id
    value = data.value
  } else {
    url = '/Employee/Search'
    value = data
  }
  return request({
    url,
    method,
    data: value
  })
}

// 员工禁用启用
export function setEmployee(method, data) {
  const url = '/Employee/SetEnable'
  return request({ url, method, data })
}

// 安全帽报警
export function safetyCatTracking(method, data, bln) {
  let url = ''
  let value = null
  if (bln) {
    url = '/SafetyCatTracking/' + data.id
    value = data.value
  } else {
    url = '/SafetyCatTracking/Search'
    value = data
  }
  return request({
    url,
    method,
    data: value
  })
}
// 报警消息 超员
export function alertOverMan(method, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/AlertOverMan/' + data.id
    value = data.value
  } else {
    url = '/AlertOverMan/Search'
    value = data
  }
  return request({
    url,
    method,
    data: value
  })
}

// 报警消息 超时
export function alertOverTime(method, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/AlertOverTime/' + data.id
    value = data.value
  } else {
    url = '/AlertOverTime/Search'
    value = data
  }
  return request({
    url,
    method,
    data: value
  })
}

// 报警消息 环境监测
export function alertSensor(method, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/AlertSensor/' + data.id
    value = data.value
  } else {
    url = '/AlertSensor/Search'
    value = data
  }
  return request({
    url,
    method,
    data: value
  })
}

// 报警消息 视频报警
export function alertVideo(method, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/AlertVideo/' + data.id
    value = data.value
  } else {
    url = '/AlertVideo/Search'
    value = data
  }
  return request({
    url,
    method,
    data: value
  })
}

// 报警消息标记为已读
export function alertHandler(type, ids) {
  const url = `/Alert/Read/${type}/${ids}`
  return request(url, 'post', '')
}

export function getAlertCount() {
  return request({ url: '/TunnelRealTime/GetAlertCount', method: 'get', params: null })
}

export function department(method, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/Department/' + data.id
    value = data.value
  } else {
    url = '/Department/Search'
    value = data
  }
  return request({
    url,
    method,
    data: value
  })
}

// 职位管理
export function job(method, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/Job/' + data.id
    value = data.value
  } else {
    url = '/Job/Search'
    value = data
  }
  return request({
    url,
    method,
    data: value
  })
}

// 工种管理
export function work(method, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/Work/' + data.id
    value = data.value
  } else {
    url = '/Work/Search'
    value = data
  }
  return request({
    url,
    method,
    data: value
  })
}

// 考勤设置
export function attendance(method, data) {
  let url = ''
  let value = ''
  method = method.toLocaleUpperCase()
  if (method === 'GET') {
    url = '/AttendanceSetting/firstOne'
  } else if (method === 'PUT') {
    url = '/AttendanceSetting/' + data.id
    value = data.value
  } else if (method === 'POST') {
    url = '/AttendanceSetting'
    value = data
  }
  return request({
    url,
    method,
    data: value
  })
}

// 区域管理
export function area(method, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/Area/' + data.id
    value = data.value
  } else {
    url = '/Area/Search'
    value = data
  }
  return request({
    url,
    method,
    data: value
  })
}

// 考勤统计
export function attendanceList(method, data, bln) {
  let url = ''
  let value = null
  if (bln) {
    url = '/Attendance/' + data.id
    value = data.value
  } else {
    url = '/Attendance/Search'
    value = data
  }
  return request({
    url,
    method,
    data: value
  })
}

// 实时定位
export function realtimeLocation(method, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/RealtimeLocation/' + data.id
    value = data.value
  } else {
    url = '/RealtimeLocation/Search'
    value = data
  }
  return request({ url, method, data: value })
}

// 轨迹回放
export function path(method, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/Path/' + data.id
    value = data.value
  } else {
    url = '/Path/Search'
    value = data
  }
  return request({ url, method, data: value })
}

// 操作日志
export function actionLog(method, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/ActionLog/' + data.id
    value = data.value
  } else {
    url = '/ActionLog/Search'
    value = data
  }
  return request({ url, method, data: value })
}

// 修改当前用户密码
export function changePassword(method, data) {
  const url = '/Auth/ChangePassword'
  return request({ url, method, data })
}

// 安全帽管理
export function safetyCatSetting(method, value) {
  let url = ''
  let data = null
  method = method.toLocaleUpperCase()
  if (method === 'POST') {
    // url = "/SafetyCatSetting/firstOne"
    url = '/SafetyCatSetting/Search'
    data = value
  } else if (method === 'PUT') {
    url = 'SafetyCatSetting/' + value.id
    data = value.value
  }
  if (value.tenant !== undefined) {
    url = url + '?tenant=' + value.tenant
  }
  return request({ url, method, data })
}

// 在线率统计
export function tenantOnline(method, value, bln) {
  let url = ''
  let data = null
  if (bln) {
    url = '/TenantOnline/AllOnlineView'
    data = value
  } else {
    url = '/TenantOnline/GetOnlineView'
    data = value
  }
  return request({ url, method, data })
}

// 隧道示意图
export function tunnelRealTime(value) {
  const url = `/TunnelRealTime`
  const method = 'GET'
  const params = { includeGate: value }
  return request({ url, method, params })
}
// 获取在线状态
export function GetOnlineStatus() {
  const url = `/TenantOnline/GetOnlineStatus`
  const method = 'GET'
  return request({ url, method })
}
// 设备图像设置
export function parameter(method, params) {
  let url = ''

  method = method.toLocaleUpperCase()
  if (method === 'GET') {
    url = '/Parameter/parameterName'
  } else if (method === 'PUT') {
    url = '/Parameter'
  }
  return request({ url, method, params })
}

// 基站
export function baseStation(method, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/BaseStation/' + data.id
    value = data.value
  } else {
    url = '/BaseStation/Search'
    value = data
  }
  return request({ url, method, data: value })
}

// 门禁
export function autoGate(method, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/AutoGate/' + data.id
    value = data.value
  } else {
    url = '/AutoGate/Search'
    value = data
  }
  return request({ url, method, data: value })
}

// 共享员工查询
export function shareEmployeeHandle(method, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/ShareEmployee/' + data.id
    value = data.value
  } else {
    url = '/ShareEmployee/Search'
    value = data
  }
  return request({ url, method, data: value })
}

// 查找备份
export function backupSettingList(method) {
  return request({ url: '/BackupSetting/firstOne', method })
}

// 设置备份
export function backupSetting(method, data) {
  return request({ url: '/BackupSetting/' + data.id, method, data })
}

// 数据备份列表
export function backupLog(method, data, bln) {
  let url = ''
  let value = null

  if (bln) {
    url = '/BackupLog/' + data.id
    value = data.value
  } else {
    url = '/BackupLog/Search'
    value = data
  }
  return request({ url, method, data: value })
}
